﻿Imports System.Data.OleDb

Public Class UserProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim username As String = Request.Params("Username")

        If Not String.IsNullOrEmpty(username) Then

            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ClubsConnectionString").ConnectionString)
            oleDbConn.Open()

            Dim selectUserSQL As String = "SELECT * FROM UserProfile WHERE Username=@f1"
            Dim selectUserCmd As OleDbCommand = New OleDbCommand(selectUserSQL, oleDbConn)
            selectUserCmd.CommandType = CommandType.Text
            selectUserCmd.Parameters.AddWithValue("@f1", username)
            Dim selectUserDr As OleDbDataReader = selectUserCmd.ExecuteReader()

            If selectUserDr.HasRows Then
                If Request.Params("Username") = User.Identity.Name Then
                    btnEditProfile.Visible = True
                Else
                    btnEditProfile.Visible = False
                End If
            Else
                Session("UserMessage_Error") = "The specified User does not exist!"
                Response.Redirect("~/AllUsers.aspx")
            End If

            selectUserCmd.Dispose()
            oleDbConn.Close()
            oleDbConn.Dispose()
        Else
            Session("UserMessage_Error") = "A user must be specified!"
            Response.Redirect("~/AllUsers.aspx")
        End If

    End Sub

End Class